frappe.listview_settings['Shoe Sample'] = {
    refresh: function(listview) {
        add_export_excel_action_items(listview);
    }
}

var add_export_excel_action_items = function (listview) {
    frappe.call({
        method: "frappe.client.get_list",
        args: {
          doctype: "Excel Export Template",
          filters: {
            "reference_doctype": listview.doctype,
            "enable_export_excel": 1,
            "for_list_view": 1
          },
          fields: ["template_file", "export_file_name", "template_name"],
          limit_page_length: 9999,	// 默认20条太少了
          as_dict: 1
        }
    }).then(r=>{
        if (!r.exc && r.message && r.message.length){
            r.message.forEach(row=>{
                listview.page.add_action_item(__(row.template_name), () => {
                    let data = listview.get_checked_items();
                    if(!data.length) {
                        frappe.show_alert(__("请至少选择一张单据"));
                        return;
                    }
                    open_url_post('/api/method/zelin_export_excel_template.api.export_data', {
                        doc: {
                            'name': 'shoe sample',
                            'data': data
                        },
                        template_file: row.template_file,
                        export_file_name: row.export_file_name || "",
                        template_name: row.template_name
                    });
                });
            })
        }
    })
}